package com.micrometa.km.ui.components;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.micrometa.km.ui.components.toolbar.ConfigDialog;
import com.micrometa.km.ui.util.IconUtil;

public class ToolBar extends JToolBar {
	private static final long serialVersionUID = 1L;

	private final JDialog configDialog = new ConfigDialog();

	public ToolBar(String label, int size, boolean hasStrings) {
		//config 
		JButton buttonConfig = new JButton(hasStrings ? "设置" : null, IconUtil
				.getIcon("/config_22"));
		buttonConfig.setToolTipText("设置基本配置");
		buttonConfig.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SwingUtilities.invokeLater(new Runnable() {
					public void run() {
						configDialog.setVisible(true);
					}
				});
			}
		});
		this.add(buttonConfig);
		//ipmsg
		JButton buttonIpmsg = new JButton("飞鸽", IconUtil
				.getIcon("/mail_22"));
		buttonIpmsg.setToolTipText("Coming soon... ..");
		buttonIpmsg.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//TODO:ipmsg
//				new MainWindow().setVisible(true);
			}
		});
		this.add(buttonIpmsg);
		buttonIpmsg.setEnabled(false);
		// exit button
		this.add(Box.createGlue());
		// add toolbar separator
		this.addSeparator();
		JButton buttonExit = new JButton("退出", IconUtil
				.getIcon("/close_22"));
		buttonExit.setToolTipText("退出程序");
		buttonExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		this.add(buttonExit);
	}
}
